/*
 DA2.c
 Design Assignment 2
 Darius Smith
 CPE 301
 */ 


#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
{
	int run = 1;			//offset to sync the period
//	TCCR1A = 0x00;			
	TCCR1B = 0x0D;			//1_101 //8-CTC mode and 5-prescaler 
	OCR1A = 1953;			//fifth rising edge happens every 2.25s
	DDRB = 0xFF;
	DDRD = 0xFF;				//allows use to all outputs to be on
	TIMSK0 |= (1 << TOIE0);    //enable timer compare interrupt
	
	sei();					//set enable interrupt
TIFR1 |= (1 << OCF1A);
    while(1)
		{	
		while ((TIFR1 & (1 << OCF1A)) == 0)	//.25second delay
			{
			}
			TIFR1 |= (1 << OCF1A);
			PORTB ^= 32;			//inverts bit 5 
			PORTD += 1;				//increments register
	
		if(((run) %5) == 0)
			{
			run = 0;
			TCNT0 = 0xFF;
			TCCR0B = 1;
			TCNT0 += 1;
			}
		while ((TIFR1 & (1 << OCF1A)) == 0 )
			{
			}	
		TIFR1 |= (1 << OCF1A);
			PORTB ^= 32;
			run++;
		}
}
ISR(TIMER0_OVF_vect)
{
	TCCR0B = 0;
	PORTB ^= 16;				//invert 
}